#include <iostream>
#include <memory>
#include <vector>

using std::cout;
using std::endl;
using std::unique_ptr;
using std::vector;

class Point
{
public:
    Point(int ix = 0, int iy = 0)
    : _ix(ix)
    , _iy(iy)
    {
        cout << "Point(int = 0, int = 0)"  << endl;
    }

    void print() const
    {
        cout << "(" << _ix
             << ", " << _iy
             << ")" << endl;
    }

    ~Point()
    {
        cout << "~Point()" << endl;
    }
private:
    int _ix;
    int _iy;
};

void test()
{
    unique_ptr<int> up(new int(10));
    cout << "*up = " << *up << endl;
    cout << "up.get() = " << up.get() << endl;

    cout << endl;
    //独享所有权的智能指针，对托管的空间独立拥有
    //在语法层面就将auto_ptr的缺陷摒弃了
    //具有对象语义
    /* unique_ptr<int> up2 = up;//error */

    cout << endl;
    unique_ptr<int> up3(new int(20));
    /* up3 = up;//error */

    cout << endl;
    vector<unique_ptr<Point>> vec;
    unique_ptr<Point> up4(new Point(10, 20));
    vec.push_back(std::move(up4));
    vec.push_back(unique_ptr<Point>(new Point(1, 3)));
}

int main(int argc, char **argv)
{
    test();
    return 0;
}

